<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class RedTimer extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'red:timer {status} {--D|daemonize=0}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '红包相关定时器';

    /**
     * 定时器id
     * @var null
     */
    private $Timer = null;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $_daemonize = $this->option('daemonize');
        switch ($this->argument('status')) {
            case 'start':
                cool_red_timer($_daemonize);
            break;
            case 'stop':
                exec('kill -9 '.Redis::get('cool_red_timer_master_pid'));
            break;
            default:
                echo "参数错误：start 或者 stop \r\n";
                exit;
        }
    }
}
